import { ReactElement, Suspense, useEffect } from "react"
import { RouterProvider } from 'react-router-dom'
import router from "./router"
import { Spin } from "antd";
import { dynamicRoutes } from "./router/lazy";

function App(): ReactElement {
  useEffect(() => {
    dynamicRoutes().then(routes => {
      if (!router.routes[0].children) return

      routes.forEach(route => {
        router.routes[0].children?.push(route)
      })

      console.log('注册路由', router)
    })
  }, [])

  return (
    <div className="w-full h-full">
      <Suspense fallback={<Spin fullscreen={true} />}>
        <RouterProvider router={router} />
      </Suspense>
    </div>
  )
}

export default App